﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;

namespace MobSoulWPhoneToolkit.Controls
{
    public partial class GoToMarketPlaceControl : UserControl
    {
        MarketplaceDetailTask detailTask;
        public GoToMarketPlaceControl()
        {
            InitializeComponent();
            detailTask = new MarketplaceDetailTask();
        }

        private string idapp1;
        public static readonly DependencyProperty idproperty = DependencyProperty.Register("IDApp", typeof(string), typeof(GoToMarketPlaceControl), new PropertyMetadata("default", onPropertychanged));
        public string IDApp
        {
            set { SetValue(idproperty, value); }
            get { return (string)GetValue(idproperty); }
        }

        private string imgsource1;
        public static readonly DependencyProperty imgsourceproperty = DependencyProperty.Register("BackGroundImage", typeof(string), typeof(GoToMarketPlaceControl), new PropertyMetadata("default", onPropertychanged));
        public string BackGroundImage
        {
            set { SetValue(imgsourceproperty, value); }
            get { return (string)GetValue(imgsourceproperty); }
        }


        public static readonly DependencyProperty nameAppproperty = DependencyProperty.Register("AppName", typeof(string), typeof(GoToMarketPlaceControl), new PropertyMetadata("default", onPropertychanged));
        public string AppName
        {
            set { SetValue(nameAppproperty, value); }
            get { return (string)GetValue(nameAppproperty); }
        }

        static void onPropertychanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            GoToMarketPlaceControl app = sender as GoToMarketPlaceControl;
            if (args.Property == imgsourceproperty)
            {
                app.imgsource1 = args.NewValue as string;
                app.BackGround.Source = new BitmapImage(new Uri(app.imgsource1, UriKind.Relative));
            }
            else if (args.Property == idproperty)
            {
                app.idapp1 = args.NewValue as string;
                app.detailTask.ContentIdentifier = app.idapp1;
            }
            else
                app.AppNameTextBlock.Text = args.NewValue as string;
        }

        private void LayoutRoot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                detailTask.Show();
            }
            catch
            {
            }
        }
    }
}
